<%
'此文件內方法已全部弃用 2008.12.28 SULei

'数据导入操作方法

'保存字串为临时的XML文件
Sub saveXMLFile(strFilename,strFileText) 
	dim fso,f

	fso = Server.MapPath("xml/"&strFilename)
	Set f = server.createobject("ADODB.Stream")
	f.Open
	f.Charset = "UTF-8"
	strFileText = Replace(Replace(strFileText,"<!DOCTYPE ML_Raidtracker PUBLIC ""-//MLdkp//DTD ML_Raidtracker V 1.5//EN"" ""http://www.mldkp.net/dtds/1.0/ML_Raidtracker.dtd"">",""), "<?xml version=""1.0""?>", "")
	strFileText = Replace(strFileText,"RaidInfo>","raidinfo>")
	strFileText = Replace(strFileText,"PlayerInfos>","playerinfos>")
	strFileText = Replace(strFileText,"BossKills>","bosskills>")
	strFileText = Replace(strFileText,"Join>","joins>")
	strFileText = Replace(strFileText,"Leave>","leaves>")
	strFileText = Replace(strFileText,"Loot>","loots>")
	strFileText = Replace(strFileText,"ItemName>","itemname>")
	strFileText = Replace(strFileText,"ItemID>","itemid>")
	strFileText = Replace(strFileText,"Icon>","icon>")
	strFileText = Replace(strFileText,"Class>","class>")
	strFileText = Replace(strFileText,"SubClass>","subclass>")
	strFileText = Replace(strFileText,"Color>","color>")
	strFileText = Replace(strFileText,"Count>","count>")
	strFileText = Replace(strFileText,"Player>","player>")
	strFileText = Replace(strFileText,"Costs>","costs>")
	strFileText = Replace(strFileText,"Time>","time>")
	strFileText = Replace(strFileText,"Zone>","zone>")
	strFileText = Replace(strFileText,"Boss>","boss>")
	strFileText = Replace(strFileText,"Note>","note>")
	f.WriteText = ("<?xml version=""1.0"" encoding=""UTF-8""?>"&strFileText)
	f.SaveToFile fso,2
	f.Close
	set fso = Nothing
end Sub

Private Function getRaidName()
	If Request.form("raid_title") <> "" then
		getRaidName = Request.form("raid_title")
	ElseIf checkIsNodeX(rtXML.selectSingleNode("note")) Then
		getRaidName = rtXML.selectSingleNode("note").text
	ElseIf checkIsNodeX(rtXML.selectSingleNode("zone")) Then
		getRaidName = rtXML.selectSingleNode("zone").text
	Else
		getRaidName = "未命名的活动"
	End If
End Function

'检查数据有效性并返回信息 
Sub checkXMLValidity()
	'RT150 MRT207
	On Error Resume Next
	Dim tempvar
	If rtXML.selectSingleNode("joins") Is Nothing Then 
		errtext=errtext& "活动缺少成员数据<br>"	
		chkerror=chkerror+1
	End If
	If rtXML.selectSingleNode("leaves") Is Nothing Then 
		errtext=errtext& "活动缺少离开人员数据<br>"	
		chkerror=chkerror+1
	End If
	If rtXML.selectSingleNode("loots") Is Nothing Then 
		errtext=errtext& "活动缺少物品拾取信息<br>"	
		chkerror=chkerror+1
	End If

	if errtext<>"" then
		showerror(errtext)
	end if


End sub

'获得活动开始时间
Private Function getRaidStartTime()
  getRaidStartTime=CDate(getTimeRT150(rtXML.getElementsByTagName("start")(0).text))
End Function

'获得活动结束时间
Private Function getRaidEndTime()
  getRaidEndTime=CDate(getTimeRT150(rtXML.getElementsByTagName("end")(0).text))
End Function

'检测是否出现缺少对象错误:424
function checkerror424() 
	if err=424 then
		checkerror424=True
		err.clear
	else
		checkerror424=False
	end if
end Function

'清理玩家表中重复的和信息不全的条目
Private Sub formatXMLPlayerinfoRT150()
	ChildrenCount = rtXML.getElementsByTagName("playerinfos")(0).childNodes.length-1
	arrPlayerList=","
	for i = 0 to ChildrenCount 
		if playerinfosXML.item(i).childNodes.length<4 then
			rtXML.getElementsByTagName("playerinfos")(0).removeChild(playerinfosXML.item(i))
			ChildrenCount=ChildrenCount-1
			i=i-1
		else
			if Instr(arrPlayerList,","&playerinfosXML.item(i).childNodes.item(0).text&",")>0 then
				rtXML.getElementsByTagName("playerinfos")(0).removeChild(playerinfosXML.item(i))
				ChildrenCount=ChildrenCount-1
				i=i-1
			else
				arrPlayerList=","&playerinfosXML.item(i).childNodes.item(0).text&arrPlayerList
			end if
		end if
		if i=ChildrenCount then exit for
	next
End Sub

'清理Joins节点中重复的条目
Private Sub formatXMLJoinsRT150()
	ChildrenCount = rtXML.getElementsByTagName("joins")(0).childNodes.length-1
	arrPlayerList=","
	for i = 0 to ChildrenCount 
		if playerXML.item(i).childNodes.length<2 then
			rtXML.getElementsByTagName("joins")(0).removeChild(playerinfosXML.item(i))
			ChildrenCount=ChildrenCount-1
			i=i-1
		else
			if Instr(arrPlayerList,","&playerXML.item(i).childNodes.item(0).text&",")>0 then
				rtXML.getElementsByTagName("joins")(0).removeChild(playerXML.item(i))
				ChildrenCount=ChildrenCount-1
				i=i-1
			else
				arrPlayerList=","&playerXML.item(i).childNodes.item(0).text&arrPlayerList
			end if
		end if
		if i=ChildrenCount then exit for
	next
End Sub

'建立Raid 或修改已有的Raid信息
Private Sub dbAddRaid()
	sql = "select * from raid where raid_concentratetime=#"&CDate(getTimeRT150(rtXML.getElementsByTagName("start")(0).text))&"#"
	rs.open sql,conn,1,3
	if rs.eof or rs.bof then
		rs.close
		sql = "select * from raid where (id is null)"
		rs.open sql,conn,1,3
			rs.addnew
			rs("raid_name")=raidNote
			rs("raid_concentratetime")=CDate(getTimeRT150(rtXML.getElementsByTagName("start")(0).text))
			rs("raid_actiontime")=CDate(getTimeRT150(rtXML.getElementsByTagName("start")(0).text))
			rs("raid_endtime")=CDate(getTimeRT150(rtXML.getElementsByTagName("end")(0).text))
			rs("raid_personnel")=40
			rs("raid_player")=""
			rs("raid_commander")= request("raid_commander")
			rs("raid_plan")= htmlencode2(request("raid_plan"))
			if rs("raid_step")=0 then
			rs("raid_step")=1
			rs("raid_ruler")=1
			rs("raid_ruler")=""
			end if
			if request("class_name")<>"" then rs("raid_class")=request("class_name")
			if request("ruler_name")<>"" then rs("raid_ruler")=request("ruler_name")
			rs.update
	'	response.write "添加新记录"
	else
		RaidID=rs("id")
			rs("raid_name")=raidNote
			'rs("raid_concentratetime")=CDate(DateE2C(rtXML.childNodes.item(0).text))
			'rs("raid_actiontime")=DateAdd("n",30,CDate(DateE2C(rtXML.childNodes.item(0).text)))
			'rs("raid_endtime")=CDate(DateE2C(rtXML.childNodes.item(3).lastchild.childNodes.item(1).text))
			if rs("raid_step")=0 then
			rs("raid_step")=1
			end if
			rs("raid_ruler")=1
			if request("class_name")<>"" then rs("raid_class")=request("class_name")
			if request("ruler_name")<>"" then rs("raid_ruler")=request("ruler_name")
			rs.update
	'	response.write "修改存在记录"
	end if
	rs.close
End Sub

'获得db中最新一条Raid记录的ID
Private Sub getLastestRaidID()
	sql = "select * from raid where raid_concentratetime=#"&CDate(getTimeRT150(rtXML.getElementsByTagName("start")(0).text))&"#"
	rs.open sql,conn,1,3
	Response.write "SQL: "&sql

	RaidID=rs("id")  'Error
	RaidEndTime=rs("raid_endtime")
	rs.close
End Sub

'删除此Raid全部事件
Private Sub clearRaidEvent(intRaidID)
	sql="Delete * from raid_event where event_raidid="&RaidID
	conn.execute (sql)
End Sub

'更新数据库中玩家信息,如果没有记录就add,如果已存在则检查基本资料是否相符,不相符则用当前数据更新之
Private Sub dbRenewPlayer(strPlayerName,strLevel,strRace,strClass,strGuildRank)
	sql="select * from player where player_name='"&strPlayerName&"'"
	rs.open sql,conn,1,3
		if rs.eof or rs.bof then
			rs.close
			sql="select * from player where (id is null)"
			rs.open sql,conn,1,3
			rs.addnew
				rs("player_name")=strPlayerName
				rs("player_level")=strLevel
				rs("player_tribe")=getFormatRaceName(strRace)
				rs("player_profession")=getFormatProfessionName(strClass)
				rs("player_guildlevel")=strGuildRank
				rs("player_honor")="无"
				rs("player_jointime")=getRaidStartTime()
				rs("player_BaseDKP")=0
				rs("player_DKP")=0
				rs("player_skill_1")="未知"
				rs("player_skill_2")="未知"
				rs("player_looted")=""
			rs.update
		else
			if rs("player_level")<>strLevel or rs("player_tribe")<>getFormatRaceName(strRace) or rs("player_profession")<>getFormatProfessionName(strClass) then
				rs("player_name")=strPlayerName
				rs("player_tribe")=getFormatRaceName(strRace)
				if strGuildRank<>"" then rs("player_guildlevel")=strGuildRank
				rs("player_profession")=getFormatProfessionName(strClass)				
				rs.update
			elseif rs("player_guildlevel")<>strGuildRank and strGuildRank<>"" then
				rs("player_guildlevel")=strGuildRank
				rs.update
			end if
		end if
	rs.close
End Sub

'获得一组角色名字的ID数组
Private Function getPlayerIDs(strPlayerList)
	strPlayerList = Split(Mid(left(strPlayerList,len(strPlayerList)-1),2),",")
	ReDim arrPlayerListNum(UBound(strPlayerList))
	sql="select * from player"
	rs3.open sql,conn,1,1
	for i = 1 to rs3.recordcount
		for j = 0 to UBound(strPlayerList)
			if rs3("player_name")=strPlayerList(j) then
			arrPlayerListNum(j)=rs3("id")
			end if
		next
		rs3.movenext
	next
	rs3.close
	getPlayerIDs=join(arrPlayerListNum,", ")
End Function


'在Raid中写入参与人员ID
Private Sub dbAddRaidPlayer(strPlayerList)
	sql = "select * from raid where id="&RaidID
	rs2.open sql,conn,1,3
	rs2("raid_player")=getPlayerIDs(strPlayerList)
	rs2.update
	rs2.close
End Sub

'数据写入加入事件
Private Sub dbADDRaidPlayerJoin(RaidID,dTime,playerName)
	rs2.addnew
	rs2("event_raidid")=RaidID
	rs2("event_time")=getTimeRT150(dTime)
	rs2("event_class")="加入"
	rs2("event_dkp")=0
	rs2("event_object")=name2idS(playerName)
	rs2("event_object2")=""
	rs2.update
End Sub

'数据写入离开事件
Private Sub dbADDRaidPlayerLeave(RaidID,dTime,playerName)
	rs2.addnew
	rs2("event_raidid")=RaidID
	rs2("event_time")=getTimeRT150(dTime)
	rs2("event_class")="离开"
	rs2("event_dkp")=0
	rs2("event_object")=name2idS(playerName)
	rs2("event_object2")=""
	rs2.update
End Sub

'数据写入首领击杀事件
Private Sub dbADDRaidBossKill(RaidID,dtime,strBossName)
	rs.addnew
	rs("event_raidid")=RaidID
	rs("event_time")=getTimeRT150(dtime)
	rs("event_class")="击杀"
	rs("event_dkp")="0"
	rs("event_object")="-"
	rs("event_object2")=strBossName
	rs.update
End Sub


'检查XMLitemNote中是否有多余信息,如果符合 *-* 格式则提取前半部,否则清空
Private Sub clearXMLItemNote(strNote)
	if Instr(itemNote,"-")>0 then
		if Instr(itemNote," - ")<>1 then
			itemNote=Left(itemNote,Instr(itemNote," - "))
		else
			itemNote=""
		end if
	else
		if len(itemNote)>0 then
			itemNote=itemNote
		else
			itemNote=""
		end if					
	end If
End Sub

'数据写入有效的物品拾取事件
Private Sub dbADDRaidLoots(strclass, cost1, cost2, O1, O2)
	rs.addnew
	rs("event_raidid")=RaidID
	rs("event_time")=getTimeRT150(itemLootTime)
	rs("event_class")= strclass
	rs("event_dkp")= cost1
	rs("event_object")=O1
	rs("event_object2")=O2
	rs("event_object2_tooltip")=""
	if cost2<>"" then rs("event_dkp2")=cost2
	if itemLootTip<>"" then rs("event_object2_tooltip")=""
	rs.update
End Sub

'获得拾取物品的最终DKP价值
Private Function getItemTrimCost(anode)
	If IsNumeric(itemNote) Then
		getItemTrimCost = itemNote
	ElseIf checkIsNodeX(anode) Then
		getItemTrimCost = anode.text
	Else
		getItemTrimCost = 0
	End If 
End Function

'判断一个节点是否存在和它是否有一个非空值,返回True or False
Private Function checkIsNodeX(aNode)
	If (Not aNode is Nothing) Then
		If aNode.text <> "" Then 
			checkIsNodeX = True
		Else
			checkIsNodeX = False
		End If
	Else
		checkIsNodeX = False
	End If
End Function
'Private Sub dbADDRaidEvent(RaidID,strEvent,strO1,strO2,intDKP,intDKP2,dTime,dkpclass,strTooltip)
'	rs2.addnew
'	rs2("event_raidid")=RaidID
'	rs2("event_time")=getTimeRT150(playerJoinTime)
'	rs2("event_class")="加入"
'	rs2("event_dkp")=0
'	rs2("event_object")=name2idS(playerName)
'	rs2("event_object2")=""
'	rs2.update
'End Sub

'=过程=================================================

'建立活动基本信息和参与成员
Sub processPlayer_RT150() 
	Response.write "开始建立活动...<br>"

	raidNote=getRaidName()

	Call formatXMLPlayerinfoRT150()
	Response.write "人员整理...<br>"
	Call dbAddRaid()
	Response.write "写入Raid记录...<br>"
	Call getLastestRaidID()
	Call clearRaidEvent(RaidID)
	Response.write "清理中...<br>"

	ChildrenCount = rtXML.getElementsByTagName("playerinfos")(0).childNodes.length-1

'	On Error Resume Next

	for i = 0 to ChildrenCount
		playerName = playerinfosXML.item(i).getElementsByTagName("name")(0).text
		playerRace = playerinfosXML.item(i).getElementsByTagName("race")(0).text
		playerClass = playerinfosXML.item(i).getElementsByTagName("class")(0).text
		playerLevel = DefalutPlayerLevel
		guildrank = ""

		Call dbRenewPlayer(playerName, playerLevel, playerRace, playerClass, "")
	next
	Response.write "成员资料补充完毕<br>"

	Call dbAddRaidPlayer(arrPlayerList)
	Response.write "活动已建立<br>"
End Sub


'加入事件处理
Sub processJoinEvents_RT150()
	Response.write "处理成员加入事件..."
	Sql="Select * from raid_event where (id is null)"
	rs2.open sql,conn,1,3
	ChildrenCount = rtXML.getElementsByTagName("joins")(0).childNodes.length-1
	for i = 0 to ChildrenCount
		playerName = playerXML.item(i).getElementsByTagName("player")(0).text
		playerJoinTime = playerXML.item(i).getElementsByTagName("time")(0).text
		if DateDiff("n",CDate(getTimeRT150(playerJoinTime)),CDate(getTimeRT150(rtXML.getElementsByTagName("start")(0).text)))<0 then
			Call dbADDRaidPlayerJoin(RaidID,playerJoinTime,playerName)
		end if
	next
	rs2.close
	Response.write "完成<br>"
End Sub

'离开相关处理
Sub processLeaveEvents_RT150() 
	Response.write "处理成员离开事件..."
	Sql="Select * from raid_event where (id is null)"
	rs2.open sql,conn,1,3
	ChildrenCount = leaveplayerXML.length-1
	for i = 0 to ChildrenCount
		if not (leaveplayerXML.item(i).childNodes.length<2) then
			leavePlayerName = rtXML.getElementsByTagName("leaves")(0).childNodes.item(i).childNodes.item(0).text
			leavePlayerTime = rtXML.getElementsByTagName("leaves")(0).childNodes.item(i).childNodes.item(1).text
			if DateDiff("n",CDate(getTimeRT150(leavePlayerTime)),RaidEndTime)>5 then
				Call dbADDRaidPlayerLeave(RaidID,leavePlayerTime,leavePlayerName)
			end if
		end if
	next
	rs2.close
	Response.write "完成<br>"
End Sub

'首领击杀事件处理
Sub processBosskillsEvents_RT150()
	Response.write "处理首领击杀事件..."
	Set BKillsXML= rXML.getElementsByTagName("bosskills")(0).childNodes
	ChildrenCount = rtXML.getElementsByTagName("bosskills")(0).childNodes.length-1  'Error
	Sql="Select * from raid_event where (id is null)"
	rs.open sql,conn,1,3
		for i = 0 to ChildrenCount
			BKname = BKillsXML.item(i).childNodes.item(0).text
			BKtime = BKillsXML.item(i).childNodes.item(1).text
			Call dbADDRaidBossKill(RaidID,BKtime,BKname)			
		next
	rs.close
	Response.write "完成<br>"
End Sub


Sub CTRT_Loot10() '物品相关处理|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
	Response.write "处理物品拾取事件..."
	ChildrenCount = rtXML.getElementsByTagName("loots")(0).childNodes.length-1

	Sql="Select * from raid_event where (id is null)"
	rs.open sql,conn,1,3
	On Error Resume Next

		for i = 0 to ChildrenCount
			itemNote=""
			itemNote2=""
			If checkIsNodeX(LootXML.item(i).selectSingleNode("note")) or checkIsNodeX(LootXML.item(i).selectSingleNode("costs")) Then
				itemNote = LootXML.item(i).getElementsByTagName("note")(0).text
				itemCosts = LootXML.item(i).getElementsByTagName("costs")(0).text
				itemName = LootXML.item(i).getElementsByTagName("itemname")(0).text
				itemID = Split(LootXML.item(i).getElementsByTagName("itemid")(0).text,":")
				itemCount = LootXML.item(i).getElementsByTagName("count")(0).text
				itemLooter = LootXML.item(i).getElementsByTagName("player")(0).text
				itemLootTime = LootXML.item(i).getElementsByTagName("time")(0).text
				
				If UBound(itemID) > 0 Then itemIDZ = itemID(0) '筛出物品ID

				Call clearXMLItemNote(itemNote)
				if Instr(itemNote,"/") then
					itemNote2=Right(itemNote,len(itemNote)-instr(itemNote,"/"))
					itemNote = Left(itemNote,instr(itemNote,"/")-1)
				end if

				for iik = 1 to Cint(itemCount)
					If IsNumeric(getItemTrimCost(LootXML.item(i).selectSingleNode("costs"))) Then 
						Call dbADDRaidLoots("拾取", getItemTrimCost(LootXML.item(i).selectSingleNode("costs")), itemNote2, name2idS(itemLooter), itemName&"#"&itemIDZ)
					ElseIf UCase(itemNote)="BOE" Then 
						Call dbADDRaidLoots("仓库",intBankItemCost,itemNote2,name2idS(itemLooter),itemName)
					Else
						Call dbADDRaidLoots("分解",0,0,name2idS(itemLooter),itemName)
					End If
				next
			End if
		next
	rs.close
	Response.write "完成<br>"
End Sub




%>